package com.dha.caodangcongnghe;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.TextView;
import android.widget.Toast;

import com.dha.asynctask.GiaoVienXemDiemAsyncTask;
import com.dha.asynctask.LayTenSinhVienAsyncTask;
import com.dha.asynctask.SinhVienXemDiemAsyncTask;
import com.dha.status.NetworkStatus;
import com.dha.ultility.QuangCao;
import com.dha.variable.ThongTinTaiKhoan;
import com.dha.variable.XemDiemVariable;

public class GiaoVienXemDiemSinhVien extends ActionBarActivity {
	
	private NetworkStatus networkStatus;
	
//	private QuangCao quangCao;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.layout_xemdiem_daydu);
		
//		quangCao = new QuangCao(this, GiaoVienXemDiemSinhVien.this);

		
		networkStatus = new NetworkStatus(getBaseContext());
		// Goi xem diem
		if (networkStatus.isConnected()) {
			GiaoVienXemDiemAsyncTask asyncTask = new GiaoVienXemDiemAsyncTask(
					GiaoVienXemDiemSinhVien.this, ThongTinTaiKhoan.maSinhVien,
					XemDiemVariable.METHOD_NAME_XEMDIEMHOCKYHIENTAI);
			asyncTask.execute();
		} else {
			Intent intentLoi = new Intent("SuCoVeKetNoiMang");
			startActivity(intentLoi);
		}
		// Vi sao khong goi cai nay?
		// vi ben giao viem xem diem co load ten sinh vien ve
		// XemDiemAsyncTask asyncTask = new
		// XemDiemAsyncTask(GiaoVienXemDiemSinhVien.this,
		// ThongTinTaiKhoan.maSinhVien,
		// XemDiemVariable.METHOD_NAME_XEMDIEMHOCKYHIENTAI);
		// asyncTask.execute();

	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.menu_xemdiem, menu);
		return true;
	}

	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		switch (item.getItemId()) {
		// case R.id.mn_XemDiem_XemTheoHocKy:
		// Intent intentDaSachHocKy = new Intent("DanhSachHocKy");
		// intentDaSachHocKy.putExtra("MaSo", ThongTinTaiKhoan.maSinhVien);
		// startActivity(intentDaSachHocKy);
		// break;
		case R.id.mn_XemDiem_XemTheoTongKet:
			if (networkStatus.isConnected()) {
				Intent itentTongKet = new Intent(
						"GiaoVienXemDiemTongKetSinhVien");
				startActivity(itentTongKet);
			} else {
				Intent intentLoi = new Intent("SuCoVeKetNoiMang");
				startActivity(intentLoi);
			}
			break;
		case R.id.mn_XemDiem_XemTheoTatCaHocKy:
			if (networkStatus.isConnected()) {
				SinhVienXemDiemAsyncTask asyncTask = new SinhVienXemDiemAsyncTask(
						GiaoVienXemDiemSinhVien.this,
						ThongTinTaiKhoan.maSinhVien,
						XemDiemVariable.METHOD_NAME_XEMDIEMTATCAHOCKY);
				asyncTask.execute();
			} else {
				Intent intentLoi = new Intent("SuCoVeKetNoiMang");
				startActivity(intentLoi);
			}
			break;
		}
		return super.onOptionsItemSelected(item);
	}

}
